package com.lun.swordtowardoffer2.c08;

import com.lun.util.BinaryTree.TreeNode;

public class SumNumbers {

	public int sumNumbers(TreeNode root) {
		return dfs(root, 0);
	}
	
	private int dfs(TreeNode node, int path) {
		if(node == null)//对单支节点
			return 0;
		
		path = path * 10 + node.val;
		
		if(node.left == null && node.right == null) {//叶子节点
			return path;
		}
		
		return dfs(node.left, path) + dfs(node.right, path); 
	}
}
